#pragma once
#include <string>
#include <fstream> //文件需单独，ca

using std::string;
using std::ifstream;
using std::ios;

#ifndef libConfigIni_H
#define libConfigIni_H
typedef unsigned uint;

class libConfigInfo
{
public:
    int ReadConfigInit(string _filename)
    {
        ifstream ifs(_filename, ios::in | ios::binary);
        if (!ifs.is_open())
        {
            return -1;
        }
        string s_local;
        while (getline(ifs, s_local))
        {
            if (s_local.find("IN_URL") == 0)
            {
                IN_URL.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1); //
            }
            else if (s_local.find("OUT_264URL") == 0)
            {
                OUT_264URL.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
            }//
            else if (s_local.find("OUT_265URL") == 0)
            {
                OUT_265URL.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
            }//
            else if (s_local.find("BufferMaxTime") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                BufferMaxTime = stoi(ss_local);
            }//
            else if (s_local.find("Caption") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                Caption = stoi(ss_local);
            }
            else if (s_local.find("Border") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                Border = stoi(ss_local);
            }//
            else if (s_local.find("WIDTH_DEN") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                WIDTH_DEN = stoi(ss_local);
            }
            else if (s_local.find("HEIGHT_DEN") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                HEIGHT_DEN = stoi(ss_local);
            }
            else if (s_local.find("Sampling") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                Sampling = stoi(ss_local);
            }
            else if (s_local.find("Bit_Rate_H264") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                Bit_Rate_H264 = stoi(ss_local);
            }
            else if (s_local.find("Bit_Rate_Tolerance_H264") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                Bit_Rate_Tolerance_H264 = stoi(ss_local);
            }
            else if (s_local.find("Bit_Rate_H265") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                Bit_Rate_H265 = stoi(ss_local);
            }
            else if (s_local.find("Bit_Rate_Tolerance_H265") == 0)
            {
                string ss_local;
                ss_local.assign(s_local, s_local.rfind("=") + 1, s_local.rfind("\r") - s_local.rfind("=") - 1);
                Bit_Rate_Tolerance_H265 = stoi(ss_local);
            }
            else if (s_local.find("BaseColor1_RGB") == 0)
            {
                string ss_local_R;
                ss_local_R.assign(s_local, s_local.rfind("R=") + 2, s_local.rfind("G=") - s_local.rfind("R=") - 3);

                string ss_local_G;
                ss_local_G.assign(s_local, s_local.rfind("G=") + 2, s_local.rfind("B=") - s_local.rfind("G=") - 3);

                string ss_local_B;
                ss_local_B.assign(s_local, s_local.rfind("B=") + 2, s_local.rfind("]") - s_local.rfind("B=") - 2);

                BaseColor1_RGB[0] = stoi(ss_local_R);
                BaseColor1_RGB[1] = stoi(ss_local_G);
                BaseColor1_RGB[2] = stoi(ss_local_B);
            }//
        }
        ifs.close();
        return 0;
    }
public:
    string    IN_URL;

    string OUT_264URL;

    string OUT_265URL;

    uint BufferMaxTime;

    uint Caption;

    uint Border;

    uint WIDTH_DEN;

    uint HEIGHT_DEN;

    uint Sampling; //取样间隔

    int64_t Bit_Rate_H264;

    uint Bit_Rate_Tolerance_H264;

    uint Bit_Rate_H265;

    uint Bit_Rate_Tolerance_H265;

    uint BaseColor1_RGB[3];//RGB
};
#endif //libConfigIni_H